/*
 * Copyright (c) 2010-2013 Ruben Chakhmakhchyan. All rights reserved.
 * 
 * This file contains Original Code and/or Modifications of Original Code
 * as defined in and that are subject to the Eclipse Public License
 * Version 1.0 (the 'License'). You may not use this file except in
 * compliance with the License. Please obtain a copy of the License at
 * http://opensource.org/licenses/EPL-1.0 and read it before using this file.
 */

#pragma once

#include "plugin_model.h"
#include "plugin.h"
#include "CScriptableControl.h"


class _Plugin : public Plugin, public MessageListener
{
public:
	_Plugin( CScriptableControl* pControl );
	~_Plugin();

public:
	PluginModel* m_model;
	CScriptableControl* m_scriptableControl;

public:

	// Plugin interface implementation
	virtual PluginModel* getModel() { return m_model; }
	virtual void setModel( PluginModel* pPluginModel ) { m_model = pPluginModel; }

	virtual void* getWindowHandle() const { return m_scriptableControl->m_hWnd; }
	virtual void updateView() { m_scriptableControl->updateView(); }

	virtual char* getUserAgent() { return m_userAgent; }
	virtual char* getUrl() { return m_scriptableControl->getUrl(); }

	virtual void setFocus() { m_scriptableControl->setFocus(); }

	virtual void onUploadComplete( int uploadId, ResultCode resultCode ) { m_scriptableControl->Fire_onUploadComplete( uploadId, ( int ) resultCode ); }
	virtual void onSaveComplete( int saveId, ResultCode resultCode ) { m_scriptableControl->Fire_onSaveComplete( saveId, ( int ) resultCode ); }
	virtual void onScanComplete( int numberOfPages ) { m_scriptableControl->Fire_onScanComplete( numberOfPages ); }
	virtual void onImageAcquired( int index ) { m_scriptableControl->Fire_onImageAcquired( index ); }
	virtual void onImageCountChanged( int count ) { m_scriptableControl->Fire_onImageCountChanged( count ); }
	virtual void onSelectedImageChanged( int index ) { 
		m_scriptableControl->Fire_onSelectedImageChanged( m_model->hasImage() ? m_model->getSelectedImageIndex() : -1 );
	}
	virtual void onImagePropertiesChanged( int index ) { m_scriptableControl->Fire_onImagePropertiesChanged( m_model->hasImage() ? index : -1 ); }
	virtual void onDeviceEvent( int event ) { m_scriptableControl->Fire_onDeviceEvent( event ); }
	virtual void onZoomChanged() { m_scriptableControl->Fire_onZoomChanged(); }
	virtual void onToolStateChanged( int id, bool state ) { m_scriptableControl->Fire_onToolStateChanged( id, state ); }

	// MessageClient interface implementation
	virtual void onMessage( char* msg ) { }
	virtual void onError( ResultCode errorCode ) { m_scriptableControl->Fire_onError( ( int ) errorCode ); }
	virtual void onDeviceConnection( bool state ) { onDeviceEvent( state ? 1 : 0 ); }

private:

	char* m_userAgent;
};
